// Srinivas Tamada http://9lessons.info
// wall.js

$(document).ready(function() 
{
					// Update Status
					$('.update_button').live("click", function() {
						var updateval = $("#update").val();
						var dataString = 'update=' + updateval;
						if (updateval == '') {
							alert("Please Enter Some Text");
						} else {
							$("#flash").show();
							$("#flash").fadeIn(400).html('Loading Update...');
							$.ajax({
								type : "POST",
								url : "wall/post",
								data : dataString,
								cache : false,
								success : function(html) {									
									$("#flash").fadeOut('slow');
									$("#wallcontent").prepend(html);
									$("#update").val('');
									$("#update").focus();
									$("#stexpand").oembed(updateval);									
								}
							});
						}
						return false;
					});

					// commment Submit

					$('.comment_button').live("click", function() 
					{
						var ID = $(this).attr("id");
						var comment = $("#ctextarea" + ID).val();
						var dataString = 'comment=' + comment + '&msg_id=' + ID;
						if (comment == '') 
						{
							alert("Please Enter Comment Text");
						} 
						else 
						{
							$.ajax({
								type : "POST",
								url : "wall/comment",
								data : dataString,
								cache : false,
								success : function(html) 
								{
									$("#commentload" + ID).append(html);
									$("#ctextarea" + ID).val('');
									$("#ctextarea" + ID).focus();
								}
							});
						}
						return false;
					});
					
					// commentopen
					$('.commentopen').live("click", function() {
						var ID = $(this).attr("id");						
						$("#commentbox" + ID).slideToggle('slow');
						return false;
					});

					// Load all comments
					$('.read_comments').live("click", function() {
						var ID = $(this).attr("id");
						var dataString = 'msg_id=' + ID;

						$.ajax({
							type : "POST",
							url : "wall/allcomments",
							data : dataString,
							cache : false,
							success : function(html) {								
								$("#read_comments" + ID).prepend(html);
								$("#streadmore" + ID).remove('');
								$("#twocomments" + ID).remove('');
							}
						});
						return false;
					});
					

						$('.loadmore').live("click", function() {
						$.ajax({
							type : "POST",
							url : "wall/loadmore",
							data : "",
							cache : false,
							success : function(html) {								
								$("#wallcontent").append(retFind(html, 'DATA'));

								if (retFind(html, 'loadedcount') == 0) {
									$('#loadmorestatus').html("&nbsp;&nbsp;No More statuses");
								}
							}
						});
						return false;
					});

					// Likes
					$('.like').live("click", function() {
						var ID = $(this).attr("id");
						var like = $(this).attr("lk");
						var dataString = 'likes=' + like+ '&msg_id=' + ID;
						$.ajax({
							type : "POST",
							url : "wall/likes",
							data : dataString,
							cache : false,
							success : function(html) {
								$("#stlikes" + ID).html(retFind(html,'DATA'));
									if (like == 1) {
										$("#likes" + ID).html("<a href='#' class='like' lk = '0' id='"+ ID
												+ "'title='unlike'>&nbsp;&nbsp;unlike&nbsp;&nbsp;- &nbsp;&nbsp; </a>");
										} else {
										$("#likes" + ID).html("<a href='#' class='like' lk = '1' id='"+ ID
													+ "'title='like'>&nbsp;&nbsp;like&nbsp;&nbsp;- &nbsp;&nbsp; </a>");
										}

									if (retFind(html, 'LIKECOUNT') == 0) 
									{
										$("#stcommentloadlikes"	+ ID).remove('');
									}
								}
							});
						return false;
					});

					// delete comment
					$('.stcommentdelete').live("click", function() 
					{
						var ID = $(this).attr("id");
						var dataString = 'com_id=' + ID;

						if (confirm("Sure you want to delete this update? There is NO undo!"))
						{
							$.ajax({
								type : "POST",
								url : "wall/deletecomment",
								data : dataString,
								cache : false,
								success : function(html) {								
								$("#stcommentbody" + ID).slideUp();
								}
							});

						}
						return false;
					});
					
					// delete update
					$('.stdelete').live("click", function() 
					{
						var ID = $(this).attr("id");
						var dataString = 'msg_id=' + ID;
						if (confirm("Sure you want to delete this update? There is NO undo!")) {
							$.ajax({
								type : "POST",
								url : "wall/deletestatus",
								data : dataString,
								cache : false,
								success : function(html) {									
									$("#stbody" + ID).slideUp();
									}
								});
							}
							return false;
						});
				});

////////////////////////////////////////////////
